const EventEmitter = require('events');

class Dog extends EventEmitter {
  constructor(name, energy) {
    super();
    this.name = name;
    this.energy = energy;
    
    const timer = setInterval(() => {
      if(this.energy > 0) {
        this.emit('bark');
        this.energy--;
      } else {
        clearInterval(timer);
      }
    }, 1000);
  }
}

module.exports = Dog;